package com.bkd.dreams.server.stand;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;

import com.bkd.dreams.client.event.VolunteerEvent;
import com.bkd.dreams.client.login.NotLoggedInException;
import com.bkd.dreams.client.stand.Stand;
import com.bkd.dreams.client.stand.StandRole;
import com.bkd.dreams.client.stand.service.StandService;
import com.bkd.dreams.server.PMF;
import com.bkd.dreams.server.core.RemoteServiceImpl;

public class StandServiceImpl extends RemoteServiceImpl implements StandService {

	@Override
	public List<Stand> getAllStands() throws NotLoggedInException {
		checkLoggedIn();
		List<Stand> results = new ArrayList<Stand>();
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			List<Stand> queryResults = (List<Stand>)pm.newQuery("select from " + Stand.class.getName()).execute();
			results.addAll(queryResults);
		} finally {
			pm.close();
		}
		return results;
	}

	@Override
	public void addStand(Stand stand) throws NotLoggedInException {
		store(stand);
	}

	@Override
	public void removeStand(Stand stand) throws NotLoggedInException {
		removeByKey(stand.getKey());
	}
}
